﻿using Mathmall.Administration.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Mathmall.Administration.Data
{
    public class BrandEntityTypeConfiguration : IEntityTypeConfiguration<Brand>
    {
        public void Configure(EntityTypeBuilder<Brand> builder)
        {
            // 不使用output子句
            builder.ToTable(table => table.UseSqlOutputClause(false));

            builder
                .ToTable(nameof(Brand))
                .ToTable(tableBuilder => tableBuilder.HasComment("品牌"));

            builder
                .HasKey(brand => brand.BrandID)
                .HasName("BrandID");

            builder
                .Property(brand => brand.Name)
                .HasColumnName("Name")
                .HasColumnType("nvarchar(50)")
                .HasComment("品牌名")
                .IsRequired();

            builder
                .Property(brand => brand.Logo)
                .HasColumnName("Logo")
                .HasColumnType("varchar(2000)")
                .HasComment("品牌logo地址")
                .IsRequired(false);

            builder
                .Property(brand => brand.Description)
                .HasColumnName("Description")
                .HasColumnType("nvarchar(2000)")
                .HasComment("介绍")
                .IsRequired(false);

            builder
                .Property(brand => brand.ShowStatus)
                .HasColumnName("ShowStatus")
                .HasColumnType("bit")
                .HasComment("显示状态[0-不显示；1-显示]")
                .IsRequired(false);

            builder
                .Property(brand => brand.FirstLetter)
                .HasColumnName("FirstLetter")
                .HasColumnType("char(1)")
                .HasComment("检索首字母")
                .IsRequired(false);

            builder
                .Property(brand => brand.Sort)
                .HasColumnName("Sort")
                .HasColumnType("int")
                .HasComment("排序")
                .IsRequired(false);

            builder
                .Property(brand => brand.CreateTime)
                .HasColumnName("CreateTime")
                .HasColumnType("datetime")
                .HasComment("创建时间")
                .IsRequired(false);

            builder
                .Property(brand => brand.LastUpdateTime)
                .HasColumnName("LastUpdateTime")
                .HasColumnType("datetime")
                .HasComment("最后更新时间")
                .IsRequired(false);
        }
    }
}